import request from '@/utils/request'

// 查询【请填写功能名称】列表
export function listManage(query) {
  return request({
    url: '/file/manage/list',
    method: 'get',
    params: query
  })
}

// 查询【请填写功能名称】详细
export function getManage(id) {
  return request({
    url: '/file/manage/' + id,
    method: 'get'
  })
}

// 新增【请填写功能名称】
export function addManage(data) {
  return request({
    url: '/file/manage',
    method: 'post',
    data: data
  })
}

// 修改【请填写功能名称】
export function updateManage(data) {
  return request({
    url: '/file/manage',
    method: 'put',
    data: data
  })
}

// 删除【请填写功能名称】
export function delManage(id) {
  return request({
    url: '/file/manage/' + id,
    method: 'delete'
  })
}


// 下载多文件
export function downLoadManage(evidenceUrl) {
  return request({
    responseType: 'blob',
    url: 'common/download/resource?resource=' + evidenceUrl,
    method: 'get'
  })
}
// 上传文件
export function uploadManage(formData) {
  return request({
    url: 'common/uploads',
    method: 'post',
    data: formData
  })
}


//文件格式校验
export function getFileType(url) {
  // 根据后缀判断文件类型
  let fileSuffix = "";
  // 结果
  let result = "";
  try {
    let flieArr = fileName.split(".");
    fileSuffix = flieArr[flieArr.length - 1];
  } catch (err) {
    fileSuffix = "";
  }
  // fileName无后缀返回 false
  if (!fileSuffix) {
    result = false;
    return result;
  }
  // 图片格式
  let imglist = ["png", "jpg", "jpeg", "bmp", "gif"];
  // 进行图片匹配
  result = imglist.some(function (item) {
    return item == fileSuffix;
  });
  if (result) {
    result = "image";
    return result;
  }
  // 匹配txt
  let txtlist = ["txt"];
  result = txtlist.some(function (item) {
    return item == fileSuffix;
  });
  if (result) {
    result = "txt";
    return result;
  }
  // 匹配 excel
  let excelist = ["xls", "xlsx"];
  result = excelist.some(function (item) {
    return item == fileSuffix;
  });
  if (result) {
    result = "excel";
    return result;
  }
  // 匹配 word
  let wordlist = ["doc", "docx"];
  result = wordlist.some(function (item) {
    return item == fileSuffix;
  });
  if (result) {
    result = "word";
    return result;
  }
  // 匹配 pdf
  let pdflist = ["pdf"];
  result = pdflist.some(function (item) {
    return item == fileSuffix;
  });
  if (result) {
    result = "pdf";
    return result;
  }
  // 匹配 ppt
  let pptlist = ["ppt"];
  result = pptlist.some(function (item) {
    return item == fileSuffix;
  });
  if (result) {
    result = "ppt";
    return result;
  }
  // 匹配 视频
  let videolist = ["mp4", "m2v", "mkv"];
  result = videolist.some(function (item) {
    return item == fileSuffix;
  });
  if (result) {
    result = "video";
    return result;
  }
  // 匹配 音频
  let radiolist = ["mp3", "wav", "wmv"];
  result = radiolist.some(function (item) {
    return item == fileSuffix;
  });
  if (result) {
    result = "radio";
    return result;
  }
  // 其他 文件类型
  result = "other";
  return result;
}

